class Component:
    def __init__(self, name):
        self.name = name

    def add(self, component): pass

    def remove(self, component): pass

    def display(self, depth): pass


class Leaf(Component):
    def __init__(self, name):
        super().__init__(name)

    def display(self, depth):
        print("-" * depth + self.name)


class Composite(Component):
    def __init__(self, name):
        super().__init__(name)
        self.children = []

    def add(self, component):
        self.children.append(component)

    def remove(self, component):
        self.children.remove(component)

    def display(self, depth):
        print("-" * depth + self.name)
        for child in self.children:
            child.display(depth + 2)


if __name__ == '__main__':
    component1 = Component("component1")
    leaf1 = Leaf("leaf1")
    leaf2 = Leaf("leaf2")
    composite1 = Composite("composite1")  # 修改了这里，将 component1 替换为 "composite1"
    composite1.add(leaf1)  # 修改了这里
    composite1.add(leaf2)  # 修改了这里
    composite1.display(2)